clear all
log using "temp", replace
use "./data.dta"


** Remove disqualified respondents **

// Refuse to participate
drop if waiver == 2 

// Age less than 18 years old (i.e. born after 1997 ["84"])
drop if yob > 84 

// Non-Chinese citizen
drop if citizen != 1  


// Module 1
gen trade = .
replace trade = 1 if (trade0 == 3 | trade1 == 3 | trade2 == 3) & trade8b == 1
replace trade = 2 if (trade0 == 3 | trade1 == 3 | trade2 == 3) & trade8b == 2
replace trade = 3 if (trade0 == 2 | trade1 == 2 | trade2 == 2)
replace trade = 4 if (trade0 == 1 | trade1 == 1 | trade2 == 1) & trade8a == 2
replace trade = 5 if (trade0 == 1 | trade1 == 1 | trade2 == 1) & trade8a == 1


tab ipe if (ipe == 1 | ipe == 2 | ipe == 7)

gen trade_prop = .
replace trade_prop = 1 if (trade == 1 | trade == 2 )
replace trade_prop = 0 if (trade == 3 | trade == 4 | trade == 5)


prtest trade_prop if ipe == 1 | ipe == 2, by(ipe) 
prtest trade_prop if ipe == 1 | ipe == 7, by(ipe) 


// Module 2
gen dump = .
replace dump = 1 if (dump3 == 2 | dump4 == 2 | dump5 == 2 | dump6 == 2) & oppose == 1
replace dump = 2 if (dump3 == 2 | dump4 == 2 | dump5 == 2 | dump6 == 2) & oppose == 2
replace dump = 3 if (dump3 == 3 | dump4 == 3 | dump5 == 3 | dump6 == 3)
replace dump = 4 if (dump3 == 1 | dump4 == 1 | dump5 == 1 | dump6 == 1) & agree == 2
replace dump = 5 if (dump3 == 1 | dump4 == 1 | dump5 == 1 | dump6 == 1) & agree == 1

gen dump_prop = .
replace dump_prop = 0 if (dump == 1 | dump == 2 | dump == 3)
replace dump_prop = 1 if (dump == 4 | dump == 5)

tab ipe if (ipe == 3 | ipe == 4 | ipe == 5 | ipe == 6)

prtest dump_prop if ipe == 4 | ipe == 6, by (ipe) 

// Module 3
gen robust = treatment
gen get = .
replace get = 1 if (get1 == 3 | get2 == 3 | get3 == 3)
replace get = 2 if (get1 == 2 | get2 == 2 | get3 == 2)
replace get = 3 if (get1 == 1 | get2 == 1 | get3 == 1)

gen get_prop = .
replace get_prop = 1 if (get == 1)
replace get_prop = 0 if (get == 2 | get == 3)

tab robust if (robust == 1 | robust == 2 | robust == 3)

prtest get_prop if robust == 2 | robust == 3, by (robust)
prtest get_prop if robust == 1 | robust == 3, by (robust)

log close
translate "temp.smcl" "results.pdf", replace
rm "temp.smcl"